package com.cn.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.cn.entity.News;
import com.cn.dao.NewsMapper;
import com.cn.service.NewsService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cn.vo.query.NewsQueryVo;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.ObjectUtils;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author hyz
 * @since 2024-10-28
 */
@Service
@Transactional
public class NewsServiceImpl extends ServiceImpl<NewsMapper, News> implements NewsService {

    @Override
    public List<News> findNewsList(NewsQueryVo newsQueryVo) {
        //创建条件构造器对象
        QueryWrapper<News> queryWrapper = new QueryWrapper<News>();
        //部门名称
        queryWrapper.like(!ObjectUtils.isEmpty(newsQueryVo.getTitle()), "title", newsQueryVo.getTitle());
        //排序
        queryWrapper.orderByAsc("id");
        //查询部门列表
        List<News> newsList = baseMapper.selectList(queryWrapper);
        return newsList;
    }

    @Override
    public boolean deleteNewsById(Long id) {
        if ( baseMapper.deleteNewsById(id) > 0) {
            return true;
        }
        return false;
    }
}
